/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.cms.helper.parser;

import java.util.List;

import com.jinhe.tss.cms.entity.ArticleScore;
import com.jinhe.tss.core.util.EasyUtils;
import com.jinhe.tss.core.web.dispaly.grid.GridNode;
import com.jinhe.tss.core.web.dispaly.grid.GridParser;

public class ArticleScoreGridParser extends GridParser {

	public GridNode parse(Object data, int dataType) {
		Object[] obj = (Object[]) data;
		List<?> list = (List<?>) obj[0];
		
		if( EasyUtils.isNullOrEmpty(list) ) return null;
		
		GridNode root = new GridNode();
		for ( int i = 0; i < list.size(); i++ ) {
			Object[] temp = (Object[]) list.get(i);
			
            ArticleScore scorer = new ArticleScore();
            scorer.setScore((Integer) temp[1]);
            scorer.setScoreCount(String.valueOf( temp[0] ));
            scorer.setAverageScore( obj[1] == null ? "0" : (String) obj[1]);
            
            root.addChild(new GridNode(scorer, this.getColumns(), dataType));
		}
		return root;
	}
}
